package com.wjk.cms.service.impl;

import com.wjk.cms.dao.CategoryRepository;
import com.wjk.cms.pojo.Category;
import com.wjk.cms.service.CategoryService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.Predicate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author WUGN
 * @des
 * @date 2021/10/12 9:15
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryRepository categoryRepository;



    @Override
    public List<Category> list() {
        return categoryRepository.findAll((root, query, cb) -> {
            List<Predicate> predicates = new ArrayList<>();


            return cb.and(predicates.toArray(new Predicate[0]));
        },Sort.by(Sort.Order.asc("createTime")));
    }

    @Override
    public Category getById(Long id) {
        return categoryRepository.getById(id);
    }
}
